package com.design.patterns.list.command;

/**
 * 具体的命令实现
 * @author Wangzhiwen
 */
public class ConcreteCommand implements Command {

    // 聚合具体命令关联的具体命令接收者
    private Receiver receiver;

    // 命令接收者的注入方式
    public ConcreteCommand(Receiver receiver) {
        this.receiver = receiver;
    }
    public void setReceiver(Receiver receiver) {
        this.receiver = receiver;
    }

    @Override
    public Object commandIdentification() {
        return "Concrete Command";
    }

    // 命令接收者执行改命令具体的逻辑
    @Override
    public void execute() {
        receiver.on();
    }

    // 命令接收者撤销改命令具体的逻辑
    @Override
    public void undo() {
        receiver.off();
    }
}
